%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%  Scientific Visualization and Virtual Reality
%       Wouter Josemans and Ninghang Hu
%               October 28, 2010
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% create elevation map from flickr data

function [histogram,photoNum] = generateMap(Start_date,End_date,lim,data)

%%%
%   Import Date from EXCEL to MATLAB
%   * change date to number in EXCEL
%   * import EXCEL sheet to MATLAB
%   * matDate = xlsDate + datenum('30-Dec-1899')
%   * use datestr and datevec to show the orignial format
        
    % remove duplicates
%     [uId,m,n] = unique(photodata(:,1));
%     uPos = pos(m,:);
    Taken_Time = data(:,4);
    
    idx = intersect(find(Taken_Time >= Start_date),find(Taken_Time <= End_date));
    photoNum = size(idx,1);
    data = data(idx,:);
    Pos = [data(:,3),data(:,2)];

    % create histogram on the surface
    histogram = hist3(Pos,[100,100]);

    % gaussian filtering
    h = fspecial('gaussian',[20,20],3);
    histogram = filter2(h,histogram,'same');
    
    % create texture
    im = imread('amsterdam_lowerResolution.jpg');
    im = flipdim(im,1);
    
    sz = size(histogram);
    [x,y] = meshgrid(1:sz(1),1:sz(2));
    surf(x,y,histogram,im, ...
            'FaceColor','texturemap', ...
            'EdgeColor','none');
  
    % set sunset as light source
    light('color',[0.6,0.3,0],'Style','infinite')
    
%     shading interp
    set(findobj(gca,'type','surface'),...
        'FaceLighting','phong')
    whitebg('black')
    if lim == false
        zlim('auto');
    else
        set(gca,'zlim',zlim)
    end
    set(gcf,'Color','black')
    lightangle(10,40);
    ambient = 0.1; diffuse = 0.50; specular = 0;
    material([ambient diffuse specular])
    rotate3d on;
    axis off;
    campos([0.500000000000000   -50.000000000000000   100.160254037844386]);

end